package com.sunbo509.www.gridview.fragment;


import android.app.Dialog;

import android.app.DialogFragment;
import android.os.Bundle;
import android.support.annotation.NonNull;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;

import com.sunbo509.www.gridview.R;

import java.util.List;


public   class dialogFragment extends DialogFragment {
    private  View view;
    private Button btn_cancal,btn_check;
    private EditText et_num, et_pwd;

    public dialogFragment() {
        // Required empty public constructor
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        // Inflate the layout for this fragment
        view=inflater.inflate(R.layout.fragment_dialog, container, false);
        initView();
        initEvent();
        return view;
    }

    protected  void initEvent(){
        btn_check.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Toast.makeText(getActivity(),"把输入的账号密码传到LayoutActivity",Toast.LENGTH_SHORT).show();
                String num=et_num.getText().toString();
                String pwd=et_pwd.getText().toString();
                InputListener listener=(InputListener)getActivity();
                listener.OninputComplete(num,pwd);
                dismiss();
            }
        });
        btn_cancal.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                dismiss();
            }
        });
    }

    protected  void initView(){
        btn_cancal=(Button)view.findViewById(R.id.btn_cannal);
        btn_check=(Button)view.findViewById(R.id.btn_check);
        et_num=(EditText)view.findViewById(R.id.et_num);
        et_pwd=(EditText)view.findViewById(R.id.et_pwd);
    }

    @NonNull
    @Override
    public Dialog onCreateDialog(Bundle savedInstanceState) {
        return super.onCreateDialog(savedInstanceState);
    }

    public interface InputListener{
        void OninputComplete(String num, String pwd);
    }


}
